/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.se2.meteocal.entity;

import it.polimi.se2.meteocal.xml.TimeAdapter;
import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import static javax.persistence.TemporalType.DATE;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;



/**
 *
 * @author Ugo
 */
@Entity

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement()
@NamedQueries({
    @NamedQuery(name = Event.findByCalendar, query = "SELECT e FROM Event e WHERE e.calendar = :calendar"),
    @NamedQuery(name = Event.findById, query = "SELECT e FROM Event e WHERE e.id = :id"),
    @NamedQuery(name = Event.findPublicByCalendar, query = "SELECT e FROM Event e WHERE e.calendar = :calendar AND e.privatee= FALSE"),
    @NamedQuery(name = Event.findAll, query = "SELECT e FROM Event e")

        
})
public class Event implements Serializable, Cloneable{
    private static final long serialVersionUID = 1L;
    public static final String findByCalendar = "Event.findByCalendar";
    public static final String findById = "Event.findById";
    public static final String findPublicByCalendar = "Event.findPublicByCalendar";
    public static final String findAll = "Event.findAll";

    @XmlAttribute
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "ID")
    private Long id;
    
    @XmlElement()
    //@Id DA ERRORE SE PRESENTE. RICHIEDE UNA EMBEED CLASS SOLO PER LE KEY
    @ManyToOne
    private Calendar calendar;
   
    @XmlAttribute
    @NotNull(message = "May not be empty")
    @Column(name = "TITLE")
    private String title;
    
    @XmlElement()
    @NotNull(message = "May not be empty")
    @ManyToOne()
    @JoinColumn(name = "LOCATION")
    private Location location;
    
    @XmlAttribute
    @NotNull(message = "May not be empty")
    @Temporal(DATE)
    @Column(name = "DATA")
    private Date data;
   
    @XmlJavaTypeAdapter(type=Time.class,value=TimeAdapter.class)
    @NotNull(message = "May not be empty")
    @Column(name = "BEGINN")
    private Time beginn;
            
    @XmlJavaTypeAdapter(type=Time.class,value=TimeAdapter.class)
    @NotNull(message = "May not be empty")
    @Column(name = "ENDD")
    private Time endd;
    
    
    @XmlAttribute
    @Column(name = "ACTIVITY", nullable=true)
    private String activity;
    
    @XmlAttribute
    private boolean outdoor;
    
    @XmlAttribute
    private boolean  privatee;
    
    public Event(){
       
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public void setTitle(String title){
        this.title = title;
    }
    
    public String getTitle(){
        return this.title;
    }
        
    public void setLocation(Location location){
        this.location=location;
    }
    
    public Location getLocation(){
        return this.location;
    }
    
    public void setData(Date data){
        this.data = data;
    }
    
    public Date getData(){
        return this.data;
    }
    
    public void setBeginn(Time beginn){
        this.beginn=beginn;
    }
    
    public Time getBeginn(){
        return this.beginn;
    }

    public void setEndd(Time endd){
        this.endd=endd;
    }
    
    public Time getEndd(){
        return this.endd;
    }
    
    public void setOutdoor(boolean outdoor) {
        this.outdoor = outdoor;
    }
 
    public boolean isOutdoor(){
        return this.outdoor;
    }
    
    public void setActivity(String activity){
        this.activity=activity;
    }
    
    public String getActivity(){
        return this.activity;
    }
    
    public boolean isPrivatee() {
        return privatee;
    }

    public void setPrivatee(boolean privatee) {
        this.privatee = privatee;
    }

    public void setCalendar(Calendar calendar)
    {
        this.calendar=calendar;
    }
 
    public Calendar getCalendar(){
        return this.calendar;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Event other = (Event) obj;
        return Objects.equals(this.id, other.id);
    }
    
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
